import 'dart:math';

import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/entity/account_bean.dart';

import 'package:jicaimao_flutter/utils/api_address.dart';
import 'package:jicaimao_flutter/utils/http_utils.dart';
import 'package:jicaimao_flutter/utils/sp_key.dart';
import 'package:jicaimao_flutter/utils/sp_utils.dart';
import 'package:jicaimao_flutter/views/mine/purchase_recordt.dart';
import 'package:jicaimao_flutter/views/mine/transfer_details.dart';
import 'package:jicaimao_flutter/widget/tab_widget.dart';

class Account extends StatefulWidget {
  @override
  _AccountState createState() => _AccountState();
}

class _AccountState extends State<Account> with TickerProviderStateMixin {
  List<AccountBeanResult> mData = List();
  int page = 1; //页码
  int typeFlag = -1; //   -1 全部 0 未到期 1 已完结 2违约
  int textState = -1; //
  int purchaseStatus = -1; //

  AnimationController _animationController;
  TabController tabController;

  final List<TabEntity> entity = [
    new TabEntity(title: '申购记录'),
    new TabEntity(title: '转取明细'),
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    String userId = SpUtils.getString(SpKey.KEY_USER_ID);
    // 网络请求数据
    _loadData(userId);
    tabController = TabController(length: 2, vsync: this);
    _animationController =
        new AnimationController(vsync: this, duration: Duration(seconds: 3));
    bool isForward = true;
    _animationController.addStatusListener((status) {
      if (status == AnimationStatus.forward) {
        isForward = true;
      } else if (status == AnimationStatus.completed ||
          status == AnimationStatus.dismissed) {
        if (isForward) {
          _animationController.reverse();
        } else {
          _animationController.forward();
        }
      } else if (status == AnimationStatus.reverse) {
        isForward = false;
      }
    });
    _animationController.forward();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Color(0xFFF6F5F5),
        appBar: AppBar(
          centerTitle: true,
          backgroundColor: Colors.white,
          leading: IconButton(
            icon: Icon(
              Icons.arrow_back_ios,
              color: Colors.grey,
            ),
            onPressed: () => Navigator.pop(context),
          ),
          title: Text(
            '账目',
            style: TextStyle(
              fontSize: 16,
              color: Colors.black,
            ),
          ),
//         bottom: TabBar(tabs: <Widget>[Tab(text: "申购记录",),Tab(text: "转取明细",)],controller: tabController,
//           labelColor: Color(0xFFE165C7),),

        ),
        
        body: TabWidget(
          onPageChanged: (position) {
            print(position);
          },
          children: <Widget>[
            ///申购记录
            Transfer_Details(),
            ///转取明细
            Purchase_Recordt(),
          ],
          entity: entity,
        ),
      ),
    );

  }



  /// 网络获取数据
  Future _loadData(String userId) async {
    String url = NetAddress.recordList;
    var data = {
      'pageIndex': page,
      'pageSize': 10,
      'userId': userId,
      'type': typeFlag
    };
    var respone = await HttpUtil().post(url, data: data);
    setState(() {});
  }
}

class TabEntity {
  final String title;

  TabEntity({@required this.title});
}
